package com.kd.juhaowan.ui.holder;

import android.annotation.SuppressLint;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;


import com.kd.juhaowan.R;
import com.kd.juhaowan.http.model.MineMessageModel;
import com.kd.juhaowan.ui.adapter.BaseViewHolder;
import com.kd.juhaowan.utils.LogUtil;

import net.lucode.hackware.magicindicator.buildins.UIUtil;

import butterknife.BindView;

public class MineMessageViewHolder extends BaseViewHolder {



    @BindView(R.id.item_message_title)
    TextView nameView;

    @BindView(R.id.item_message_time)
    TextView timeView;

    @BindView(R.id.item_message_tag)
    LinearLayout tagView;


    private LinearLayout.LayoutParams params;



    public MineMessageViewHolder(@NonNull View itemView) {
        super(itemView);
        params =new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.rightMargin= UIUtil.dip2px(getContext(),5);
    }



    @SuppressLint("ResourceType")
    public void setDate(MineMessageModel model){
        nameView.setText(model.getName());
        timeView.setText(model.getCreatetime().contains(" ")?model.getCreatetime().split(" ")[0]:model.getCreatetime());
        String[] tags =model.getTags_text();
        LogUtil.debugLog("dafa"+tags==null?"null":tags.length+"");
        if(tags!=null&&tags.length>0){
            tagView.setVisibility(View.VISIBLE);
            tagView.removeAllViews();
            for (String adb:tags) {
                TextView tv=new TextView(getContext());
                tv.setGravity(Gravity.CENTER);
                tv.setBackgroundResource(R.drawable.tag_bg);
                tv.setPadding(UIUtil.dip2px(getContext(),5),0,UIUtil.dip2px(getContext(),5),0);
                tv.setText(adb);
                tv.setTextColor(getContext().getColor(R.color.login_edit_hint));
                tv.setTextSize(11);
                tagView.addView(tv,params);
            }


//            searchHistoryAdapter.resetAdapterData(Arrays.asList(tags));
        }else {
            tagView.setVisibility(View.GONE);
        }
    }


}
